package org.lex.io.filesystem;

import java.io.File;
import java.util.Comparator;

/**
 * �����ļ�����бȽϣ����������У� �ļ��� < �ļ�
 * 
 * @author Daniel Liu
 */
public class FileNameComparator implements Comparator<File> {
	private static final FileNameComparator instance = new FileNameComparator();

	public static FileNameComparator getInstance() {
		return instance;
	}

	public int compare(File f1, File f2) {
		if (f1 == f2)
			return 0;
		if (null == f1)
			return null == f2 ? 0 : 1;
		if (null == f2)// now f1 != null && f2 == null
			return -1;
		// ====================================
		boolean aIsFolder = f1.isDirectory();
		if (aIsFolder != f2.isDirectory())
			return aIsFolder ? -1 : 1;
		return f1.compareTo(f2);
	}
}
